# -*- coding: utf-8 -*-

import os
import configparser


# 获取测试用例静态配置文件路径
__config_path__ = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'config')


class MyConfigParser(object):
    """
    静态文件读取器
    """

    _instance = None

    def __init__(self, config_path=None):
        self.config_file = config_path if config_path else __config_path__
        self.conf = self.config_parser()

    def config_parser(self):
        conf = configparser.ConfigParser()
        conf.read(self.config_file, encoding='utf-8')
        return conf

    def __getattr__(self, item):
        if hasattr(self.conf, item):
            return getattr(self.conf, item)
        raise AttributeError

    def get(self, section, option, raw=False, vars=None):
        try:
            resp = self.conf.get(section, option, raw=raw, vars=vars)
        except configparser.NoSectionError:
            resp = None
        except configparser.NoOptionError:
            resp = None
        return resp


if __name__ == '__main__':
    conf = MyConfigParser()
    print(123)
